/**
 * 
 */
package se.isenman.pad;

import java.awt.AWTException;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

/**
 * @author lusta
 *
 */
public class ControlPADRobot implements ITCPPADFunctions {

	private Robot robot;
	private String osName;
	
	/**
	 * 
	 */
	public ControlPADRobot() {
		try {
			robot = new Robot();
			osName = System.getProperty("os.name");
		} catch (AWTException e) {
		}
	}

	@Override
	public int move(int deplacementX, int deplacementY) {
		PointerInfo a = MouseInfo.getPointerInfo();
		Point b  = a.getLocation();
		int x = (int)b.getX();
		int y = (int)b.getY();
	  
                robot.mouseMove( x + deplacementX, y + deplacementY);
		
		return 0;
	}

	@Override
	public int leftClick() {
		robot.mousePress(InputEvent.BUTTON1_MASK);
		robot.mouseRelease(InputEvent.BUTTON1_MASK);
		
		return 0;
	}

	@Override
	public int rightClick() {
		robot.mousePress(InputEvent.BUTTON2_MASK);
		robot.mouseRelease(InputEvent.BUTTON2_MASK);
		
		return 0;
	}

	@Override
	public int doubleClick() {
		robot.mousePress(InputEvent.BUTTON1_MASK);
		robot.mouseRelease(InputEvent.BUTTON1_MASK);
		
		robot.mousePress(InputEvent.BUTTON1_MASK);
		robot.mouseRelease(InputEvent.BUTTON1_MASK);
		
		return 0;
	}
}
